/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MaltFrame.java
 *
 * Created on Mar 9, 2011, 1:37:48 PM
 */

package gbbmgmt;

import org.jdesktop.application.Action;
import java.util.*;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class MaltFrame extends javax.swing.JFrame {

    public ArrayList<String[]> Malt;
    public ArrayList<String[]> Vendor;
    public ArrayList<String[]> StockCode;


    /** Creates new form MaltFrame */
    public MaltFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxMalt = new javax.swing.JComboBox();
        jButtonLast = new javax.swing.JButton();
        jButtonNext = new javax.swing.JButton();
        jButtonPrev = new javax.swing.JButton();
        jButtonFirst = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabelMaltID = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldMaltName = new javax.swing.JTextField();
        jTextFieldMaltColor = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldMaltSG = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldMaltEff = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldMaltBagLbs = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jComboBoxVendor = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabelMaltOnHand = new javax.swing.JLabel();
        jLabelMaltSpoken = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jButtonUpdate = new javax.swing.JButton();
        jButtonNew = new javax.swing.JButton();
        jButtonSubmit = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jLabelscode = new javax.swing.JLabel();
        jLabelStockCode = new javax.swing.JLabel();
        jLabelWearhouse = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jComboBoxMalt.setName("jComboBoxMalt"); // NOI18N
        jComboBoxMalt.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxMaltPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(MaltFrame.class, this);
        jButtonLast.setAction(actionMap.get("LastRecord")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(MaltFrame.class);
        jButtonLast.setText(resourceMap.getString("jButtonLast.text")); // NOI18N
        jButtonLast.setName("jButtonLast"); // NOI18N

        jButtonNext.setAction(actionMap.get("NextRecord")); // NOI18N
        jButtonNext.setText(resourceMap.getString("jButtonNext.text")); // NOI18N
        jButtonNext.setName("jButtonNext"); // NOI18N

        jButtonPrev.setAction(actionMap.get("PrevRecord")); // NOI18N
        jButtonPrev.setText(resourceMap.getString("jButtonPrev.text")); // NOI18N
        jButtonPrev.setName("jButtonPrev"); // NOI18N

        jButtonFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        jButtonFirst.setText(resourceMap.getString("jButtonFirst.text")); // NOI18N
        jButtonFirst.setName("jButtonFirst"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabelMaltID.setText(resourceMap.getString("jLabelMaltID.text")); // NOI18N
        jLabelMaltID.setName("jLabelMaltID"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldMaltName.setText(resourceMap.getString("jTextFieldMaltName.text")); // NOI18N
        jTextFieldMaltName.setName("jTextFieldMaltName"); // NOI18N

        jTextFieldMaltColor.setText(resourceMap.getString("jTextFieldMaltColor.text")); // NOI18N
        jTextFieldMaltColor.setName("jTextFieldMaltColor"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldMaltSG.setName("jTextFieldMaltSG"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jTextFieldMaltEff.setName("jTextFieldMaltEff"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldMaltBagLbs.setName("jTextFieldMaltBagLbs"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jComboBoxVendor.setName("jComboBoxVendor"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabelMaltOnHand.setText(resourceMap.getString("jLabelMaltOnHand.text")); // NOI18N
        jLabelMaltOnHand.setName("jLabelMaltOnHand"); // NOI18N

        jLabelMaltSpoken.setText(resourceMap.getString("jLabelMaltSpoken.text")); // NOI18N
        jLabelMaltSpoken.setName("jLabelMaltSpoken"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        jButtonUpdate.setAction(actionMap.get("UpdateMalt")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonNew.setAction(actionMap.get("NewMalt")); // NOI18N
        jButtonNew.setText(resourceMap.getString("jButtonNew.text")); // NOI18N
        jButtonNew.setName("jButtonNew"); // NOI18N

        jButtonSubmit.setAction(actionMap.get("SubmitMalt")); // NOI18N
        jButtonSubmit.setText(resourceMap.getString("jButtonSubmit.text")); // NOI18N
        jButtonSubmit.setName("jButtonSubmit"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitMalt")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jLabelscode.setText(resourceMap.getString("jLabelscode.text")); // NOI18N
        jLabelscode.setName("jLabelscode"); // NOI18N

        jLabelStockCode.setText(resourceMap.getString("jLabelStockCode.text")); // NOI18N
        jLabelStockCode.setName("jLabelStockCode"); // NOI18N

        jLabelWearhouse.setText(resourceMap.getString("jLabelWearhouse.text")); // NOI18N
        jLabelWearhouse.setName("jLabelWearhouse"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel7)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldMaltName, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextFieldMaltColor, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextFieldMaltBagLbs, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel8)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxVendor, 0, 262, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextFieldMaltSG, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldMaltEff, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6)))))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelMaltID, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 208, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelWearhouse)
                .addGap(18, 18, 18)
                .addComponent(jLabelscode)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelStockCode)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxMalt, 0, 276, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLast)
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelMaltOnHand, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelMaltSpoken, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(305, Short.MAX_VALUE))
            .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSubmit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 162, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButtonLast)
                    .addComponent(jButtonNext)
                    .addComponent(jButtonPrev)
                    .addComponent(jButtonFirst)
                    .addComponent(jComboBoxMalt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelMaltID)
                    .addComponent(jLabelStockCode)
                    .addComponent(jLabelscode)
                    .addComponent(jLabelWearhouse)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldMaltName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldMaltColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldMaltSG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldMaltEff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldMaltBagLbs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxVendor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabelMaltOnHand))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabelMaltSpoken))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonUpdate)
                    .addComponent(jButtonNew)
                    .addComponent(jButtonSubmit)
                    .addComponent(jButtonExit))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxMaltPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxMaltPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxMalt.getSelectedItem().toString();

        for(String s[] : Malt){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetMaltData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }//GEN-LAST:event_jComboBoxMaltPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MaltFrame().setVisible(true);
            }
        });
    }

    public void LoadList(){
        //Remove all vendors in list.
        jComboBoxMalt.removeAllItems();

        DBA.openDBCon();
        Malt = DBA.RunSQLQuery("SELECT MaltID,MaltName FROM Malt");
        Vendor = DBA.RunSQLQuery("SELECT VID,VName From Vendors");
        StockCode = DBA.RunSQLQuery("SELECT StockID,WHID,TableID From StockCode");
        DBA.closeDBCon();

        for(String s[] : Malt){
            jComboBoxMalt.addItem(s[1]);
        }

        for(String s[] : Vendor){
            jComboBoxVendor.addItem(s[1]);
        }

        //Hide submit button.
        jButtonSubmit.setVisible(false);

        LastRecord();
    }

    @Action
    public void LastRecord() {
        jComboBoxMalt.setSelectedIndex(jComboBoxMalt.getItemCount()-1);

        String Itm = jComboBoxMalt.getSelectedItem().toString();

        for(String s[] : Malt){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetMaltData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    public void SetData(){
        jLabelMaltID.setText(Integer.toString(DBA.MaltID));
        jTextFieldMaltName.setText(DBA.MaltName);
        jTextFieldMaltColor.setText(Float.toString(DBA.MaltColor));
        jTextFieldMaltSG.setText(Integer.toString(DBA.MaltSG));
        jTextFieldMaltEff.setText(Integer.toString(DBA.MaltEff));
        jTextFieldMaltBagLbs.setText(Integer.toString(DBA.MaltBagLbs));

        jLabelMaltOnHand.setText(Float.toString(DBA.MaltOnHand) + " Lbs.");
        jLabelMaltSpoken.setText(Float.toString(DBA.MaltSpoken) + " Lbs.");

        DBA.openDBCon();
        String scode = DBA.ReturnStockCode(jLabelWearhouse.getText(), jLabelMaltID.getText());
        String StockNumber = String.format("%05d", Integer.parseInt(scode));
        DBA.GetStockCodeData(scode);
        DBA.closeDBCon();

        for(String s[] : Vendor){
            if (s[0].equals(Integer.toString(DBA.StockVendID))) {
                jComboBoxVendor.setSelectedItem(s[1]);
            }
        }

        jLabelStockCode.setText(StockNumber);
    }

    @Action
    public void FirstRecord() {
        jComboBoxMalt.setSelectedIndex(0);

        String Itm = jComboBoxMalt.getSelectedItem().toString();

        for(String s[] : Malt){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetMaltData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void NextRecord() {
        if(jComboBoxMalt.getSelectedIndex() <= (jComboBoxMalt.getItemCount()-2)){
            jComboBoxMalt.setSelectedIndex(jComboBoxMalt.getSelectedIndex()+1);
        }

        String Itm = jComboBoxMalt.getSelectedItem().toString();

        for(String s[] : Malt){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetMaltData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void PrevRecord() {
        if(jComboBoxMalt.getSelectedIndex()>=1){
            jComboBoxMalt.setSelectedIndex(jComboBoxMalt.getSelectedIndex()-1);
        }

        String Itm = jComboBoxMalt.getSelectedItem().toString();

        for(String s[] : Malt){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetMaltData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void ExitMalt() {
        dispose();
    }

    @Action
    public void NewMalt() {
        //Show Submit button.
        jButtonSubmit.setVisible(true);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(false);
        jButtonNew.setVisible(false);
        jButtonFirst.setVisible(false);
        jButtonLast.setVisible(false);
        jButtonNext.setVisible(false);
        jButtonPrev.setVisible(false);
        jComboBoxMalt.setVisible(false);
        jLabelMaltID.setVisible(false);
        jLabel1.setVisible(false);
        jLabelStockCode.setVisible(false);
        jLabelscode.setVisible(false);

        //Set text in all fields to blank.
        jLabelMaltID.setText("");
        jTextFieldMaltName.setText("");
        jTextFieldMaltColor.setText("");
        jTextFieldMaltSG.setText("");
        jTextFieldMaltEff.setText("72");
        jTextFieldMaltBagLbs.setText("");

        jLabelMaltOnHand.setText("0 Lbs.");
        jLabelMaltSpoken.setText("0 Lbs.");
    }

    @Action
    public void SubmitMalt() {
        int response = JOptionPane.showConfirmDialog(null,
                "Warning, this record will be added to the database, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);
        if (response == 0){

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String fields = "MaltName,MaltColor,MaltSG,MaltEff,MaltBagLbs";
            String query = "'" +
                jTextFieldMaltName.getText() + "','" +
                jTextFieldMaltColor.getText() + "','" +
                jTextFieldMaltSG.getText() + "','" +
                jTextFieldMaltEff.getText() + "','" +
                jTextFieldMaltBagLbs.getText() + "'";

            DBA.openDBCon();
            DBA.RunSQLInsertQuery("Malt",fields,query);
            //String MaID = DBA.GetLastIndex("Malt", "MaltID");
            String MaID = Integer.toString(Global.lastInsertID);
            DBA.closeDBCon();
            
            DBA.openDBCon();
            String WhID = "100";
            fields = "TableID,WHID,StockVendID";
            query = "'" + MaID + "','" + WhID + "','" + VID + "'";
            DBA.RunSQLInsertQuery("StockCode",fields,query);
            DBA.closeDBCon();
        }
        
        //Show Submit button.
        jButtonSubmit.setVisible(false);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(true);
        jButtonNew.setVisible(true);
        jButtonFirst.setVisible(true);
        jButtonLast.setVisible(true);
        jButtonNext.setVisible(true);
        jButtonPrev.setVisible(true);
        jComboBoxMalt.setVisible(true);
        jLabelMaltID.setVisible(true);
        jLabel1.setVisible(true);
        jLabelStockCode.setVisible(true);
        jLabelscode.setVisible(true);

        LoadList();
    }

    @Action
    public void UpdateMalt() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify vendor data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String MaltID = jLabelMaltID.getText();

            String query = "UPDATE Malt SET MaltName='" +
                        jTextFieldMaltName.getText() + "',MaltColor='" +
                        jTextFieldMaltColor.getText() + "',MaltSG='" +
                        jTextFieldMaltSG.getText() + "',MaltEff='" +
                        jTextFieldMaltEff.getText() + "',MaltBagLbs='" +
                        jTextFieldMaltBagLbs.getText() + "' WHERE MaltID = '" + MaltID + "'";
            DBA.RunSQLUpdateQuery(query);
            
            int StID = Integer.parseInt(jLabelStockCode.getText());

            query = "UPDATE StockCode SET StockVendID='" +
                    VID + "' WHERE StockID = '" + Integer.toString(StID) + "'";
            DBA.RunSQLUpdateQuery(query);

            DBA.closeDBCon();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonFirst;
    private javax.swing.JButton jButtonLast;
    private javax.swing.JButton jButtonNew;
    private javax.swing.JButton jButtonNext;
    private javax.swing.JButton jButtonPrev;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBoxMalt;
    private javax.swing.JComboBox jComboBoxVendor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelMaltID;
    private javax.swing.JLabel jLabelMaltOnHand;
    private javax.swing.JLabel jLabelMaltSpoken;
    private javax.swing.JLabel jLabelStockCode;
    private javax.swing.JLabel jLabelWearhouse;
    private javax.swing.JLabel jLabelscode;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextFieldMaltBagLbs;
    private javax.swing.JTextField jTextFieldMaltColor;
    private javax.swing.JTextField jTextFieldMaltEff;
    private javax.swing.JTextField jTextFieldMaltName;
    private javax.swing.JTextField jTextFieldMaltSG;
    // End of variables declaration//GEN-END:variables

}
